/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "zobjects_gtk.h"

ZlangInvokeFunction ZlangInvokeFunction_guispinbutton_Create_guiwindow_int_int_int_int_int_functionptr;
int ZlangInvokeFunction_guispinbutton_Create_guiwindow_int_int_int_int_int_functionptr( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject				*in3 = GetInputParameterInLocalObjectStack(rt,3) ;
	struct ZlangObject				*in4 = GetInputParameterInLocalObjectStack(rt,4) ;
	struct ZlangObject				*in5 = GetInputParameterInLocalObjectStack(rt,5) ;
	struct ZlangObject				*in6 = GetInputParameterInLocalObjectStack(rt,6) ;
	struct ZlangObject				*in7 = GetInputParameterInLocalObjectStack(rt,7) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						value ;
	int32_t						lower ;
	int32_t						upper ;
	int32_t						step_increment ;
	int32_t						digits ;
	GtkAdjustment					*adjustment = NULL ;
	struct ZlangDirectProperty_guispinbutton	*guispinbutton_direct_prop = GetObjectDirectProperty(out1) ;
	struct ZlangDirectProperty_guiwidget_common	*guispinbutton_common = & (guispinbutton_direct_prop->common) ;

	CallRuntimeFunction_int_GetIntValue( rt , in2 , & value );
	CallRuntimeFunction_int_GetIntValue( rt , in3 , & lower );
	CallRuntimeFunction_int_GetIntValue( rt , in4 , & upper );
	CallRuntimeFunction_int_GetIntValue( rt , in5 , & step_increment );
	CallRuntimeFunction_int_GetIntValue( rt , in6 , & digits );

	adjustment = gtk_adjustment_new( value , lower , upper , step_increment , 0.00 , 0 ) ;
	EVAL_GTK_WIDGET_NEW_IN_CREATE( guispinbutton_common->gtk_widget , gtk_spin_button_new(adjustment,0.00,digits) )
	SET_CONTROL_DEFAULT_STYLE( in1 , guispinbutton_common->gtk_widget )
	
	TRANSFER_INPUT_OBJECT_TO_NEW_OBJECT( guispinbutton_common->guiwindow_obj , in1 )

	ADD_CONTROL_GENERAL_CALLBACK_IN_CREATE( guispinbutton_common->guiwindow_obj , out1 , GTK_EVENT_VALUE_CHANGED , in7 )

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guispinbutton_Create_guiwindow_double_double_double_double_int_functionptr;
int ZlangInvokeFunction_guispinbutton_Create_guiwindow_double_double_double_double_int_functionptr( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject				*in3 = GetInputParameterInLocalObjectStack(rt,3) ;
	struct ZlangObject				*in4 = GetInputParameterInLocalObjectStack(rt,4) ;
	struct ZlangObject				*in5 = GetInputParameterInLocalObjectStack(rt,5) ;
	struct ZlangObject				*in6 = GetInputParameterInLocalObjectStack(rt,6) ;
	struct ZlangObject				*in7 = GetInputParameterInLocalObjectStack(rt,7) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	double						value ;
	double						lower ;
	double						upper ;
	double						step_increment ;
	int32_t						digits ;
	GtkAdjustment					*adjustment = NULL ;
	struct ZlangDirectProperty_guispinbutton	*guispinbutton_direct_prop = GetObjectDirectProperty(out1) ;
	struct ZlangDirectProperty_guiwidget_common	*guispinbutton_common = & (guispinbutton_direct_prop->common) ;

	CallRuntimeFunction_double_GetDoubleValue( rt , in2 , & value );
	CallRuntimeFunction_double_GetDoubleValue( rt , in3 , & lower );
	CallRuntimeFunction_double_GetDoubleValue( rt , in4 , & upper );
	CallRuntimeFunction_double_GetDoubleValue( rt , in5 , & step_increment );
	CallRuntimeFunction_int_GetIntValue( rt , in6, & digits );

	adjustment = gtk_adjustment_new( value , lower , upper , step_increment , 0.00 , 0 ) ;
	EVAL_GTK_WIDGET_NEW_IN_CREATE( guispinbutton_common->gtk_widget , gtk_spin_button_new(adjustment,0.00,digits) )
	SET_CONTROL_DEFAULT_STYLE( in1 , guispinbutton_common->gtk_widget )

	TRANSFER_INPUT_OBJECT_TO_NEW_OBJECT( guispinbutton_common->guiwindow_obj , in1 )

	ADD_CONTROL_GENERAL_CALLBACK_IN_CREATE( guispinbutton_common->guiwindow_obj , out1 , GTK_EVENT_VALUE_CHANGED , in7 )

	return 0;
}

ZLANG_INVOKE_FUNCTION_guiwidget_all_common_functions( spinbutton )

ZLANG_INVOKE_FUNCTION_guictl_all_common_functions( spinbutton )

ZlangInvokeFunction ZlangInvokeFunction_guispinbutton_GetIntValue;
int ZlangInvokeFunction_guispinbutton_GetIntValue( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guispinbutton	*guispinbutton_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						value ;

	value = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(guispinbutton_direct_prop->common.gtk_widget) ) ;
	CallRuntimeFunction_int_SetIntValue( rt , out1 , value );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guispinbutton_GetDoubleValue;
int ZlangInvokeFunction_guispinbutton_GetDoubleValue( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guispinbutton	*guispinbutton_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	double						value ;

	value = gtk_spin_button_get_value( GTK_SPIN_BUTTON(guispinbutton_direct_prop->common.gtk_widget) ) ;
	CallRuntimeFunction_double_SetDoubleValue( rt , out1 , value );

	return 0;
}

ZlangCreateDirectPropertyFunction ZlangCreateDirectProperty_guispinbutton;
void *ZlangCreateDirectProperty_guispinbutton( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guispinbutton	*guispinbutton_prop = NULL ;
	struct ZlangDirectProperty_guiwidget_common	*guispinbutton_common = NULL ;
	
	guispinbutton_prop = (struct ZlangDirectProperty_guispinbutton *)ZLMALLOC( sizeof(struct ZlangDirectProperty_guispinbutton) ) ;
	if( guispinbutton_prop == NULL )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_ALLOC , "alloc memory for entity" )
		return NULL;
	}
	memset( guispinbutton_prop , 0x00 , sizeof(struct ZlangDirectProperty_guispinbutton) );

	guispinbutton_common = (struct ZlangDirectProperty_guiwidget_common *)guispinbutton_prop ;
	guispinbutton_common->gtk_widget_type_id = GTK_TYPE_SPIN_BUTTON ;

	INIT_ZLANGDIRECTPROPERTY_guiwidget_common(guispinbutton)
	
	return guispinbutton_prop;
}

ZlangDestroyDirectPropertyFunction ZlangDestroyDirectProperty_guispinbutton;
void ZlangDestroyDirectProperty_guispinbutton( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guispinbutton	*guispinbutton_direct_prop = GetObjectDirectProperty(obj) ;
	
	CLEAN_ZLANGDIRECTPROPERTY_guiwidget_common(guispinbutton)

	ZLFREE( guispinbutton_direct_prop );
	
	return;
}

ZlangSummarizeDirectPropertySizeFunction ZlangSummarizeDirectPropertySize_guispinbutton;
void ZlangSummarizeDirectPropertySize_guispinbutton( struct ZlangRuntime *rt , struct ZlangObject *obj , size_t *summarized_obj_size , size_t *summarized_direct_prop_size )
{
	SUMMARIZE_SIZE( summarized_direct_prop_size , sizeof(struct ZlangDirectProperty_guispinbutton) )
	return;
}

static struct ZlangDirectFunctions direct_funcs_guispinbutton =
	{
		ZLANG_OBJECT_guispinbutton , /* char *ancestor_name */
		
		ZlangCreateDirectProperty_guispinbutton , /* ZlangCreateDirectPropertyFunction *create_entity_func */
		ZlangDestroyDirectProperty_guispinbutton , /* ZlangDestroyDirectPropertyFunction *destroy_entity_func */
		
		NULL , /* ZlangFromCharPtrFunction *from_char_ptr_func */
		NULL , /* ZlangToStringFunction *to_string_func */
		NULL , /* ZlangFromDataPtrFunction *from_data_ptr_func */
		NULL , /* ZlangGetDataPtrFunction *get_data_ptr_func */
		
		NULL , /* ZlangOperatorFunction *oper_PLUS_func */
		NULL , /* ZlangOperatorFunction *oper_MINUS_func */
		NULL , /* ZlangOperatorFunction *oper_MUL_func */
		NULL , /* ZlangOperatorFunction *oper_DIV_func */
		NULL , /* ZlangOperatorFunction *oper_MOD_func */
		
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NEGATIVE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NOT_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_BIT_REVERSE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_PLUS_PLUS_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_MINUS_MINUS_func */
		
		NULL , /* ZlangCompareFunction *comp_EGUAL_func */
		NULL , /* ZlangCompareFunction *comp_NOTEGUAL_func */
		NULL , /* ZlangCompareFunction *comp_LT_func */
		NULL , /* ZlangCompareFunction *comp_LE_func */
		NULL , /* ZlangCompareFunction *comp_GT_func */
		NULL , /* ZlangCompareFunction *comp_GE_func */
		
		NULL , /* ZlangLogicFunction *logic_AND_func */
		NULL , /* ZlangLogicFunction *logic_OR_func */
		
		NULL , /* ZlangLogicFunction *bit_AND_func */
		NULL , /* ZlangLogicFunction *bit_XOR_func */
		NULL , /* ZlangLogicFunction *bit_OR_func */
		NULL , /* ZlangLogicFunction *bit_MOVELEFT_func */
		NULL , /* ZlangLogicFunction *bit_MOVERIGHT_func */
		
		ZlangSummarizeDirectPropertySize_guispinbutton , /* ZlangSummarizeDirectPropertySizeFunction *summarize_direct_prop_size_func */
	} ;

ZlangImportObjectFunction ZlangImportObject_guispinbutton;
struct ZlangObject *ZlangImportObject_guispinbutton( struct ZlangRuntime *rt )
{
	struct ZlangObject	*obj = NULL ;
	struct ZlangFunction	*func = NULL ;
	int			nret = 0 ;
	
	nret = ImportObject( rt , & obj , ZLANG_OBJECT_guispinbutton , & direct_funcs_guispinbutton , sizeof(struct ZlangDirectFunctions) , NULL ) ;
	if( nret )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_LINK_FUNC_TO_ENTITY , "import object to global objects heap" )
		return NULL;
	}
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guispinbutton_Create_guiwindow_int_int_int_int_int_functionptr , ZLANG_OBJECT_guispinbutton , "Create" , ZLANG_OBJECT_guiwindow,NULL , ZLANG_OBJECT_int,NULL , ZLANG_OBJECT_int,NULL , ZLANG_OBJECT_int,NULL , ZLANG_OBJECT_int,NULL , ZLANG_OBJECT_int,NULL , ZLANG_OBJECT_functionptr,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guispinbutton_Create_guiwindow_double_double_double_double_int_functionptr , ZLANG_OBJECT_guispinbutton , "Create" , ZLANG_OBJECT_guiwindow,NULL , ZLANG_OBJECT_double,NULL , ZLANG_OBJECT_double,NULL , ZLANG_OBJECT_double,NULL , ZLANG_OBJECT_double,NULL , ZLANG_OBJECT_int,NULL , ZLANG_OBJECT_functionptr,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	ADD_FUNCTION_AND_PARAMETERS_IN_OBJECT_guiwidget_all_common_functions( spinbutton )

	ADD_FUNCTION_AND_PARAMETERS_IN_OBJECT_guictl_all_common_functions( spinbutton )

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guispinbutton_GetIntValue , ZLANG_OBJECT_int , "GetIntValue" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guispinbutton_GetDoubleValue , ZLANG_OBJECT_double , "GetDoubleValue" , NULL ) ;
	if( func == NULL )
		return NULL;

	return obj ;
}

